#define _CRT_SECURE_NO_WARNINGS 1

#include"SqQueue.h"

void InitQueue(SqQueue** q)
{
	SqQueue* newqueue = (SqQueue*)malloc(sizeof(SqQueue));
	if (newqueue == NULL)
	{
		perror("newqueue malloc:");
		*q = NULL;
	}
	newqueue->front = 0;
	newqueue->rear = 0;
	*q = newqueue;
}

bool enQueue(SqQueue* q, ElemType e)
{
	assert(q);
	if (q->front == (q->rear + 1) % (MaxSize + 1))
	{
		return false;
	}
	q->data[q->rear] = e;
	q->rear++;
	q->rear %= (MaxSize + 1);
	return true;
}

bool QueueEmpty(SqQueue* q)
{
	assert(q);
	return q->front == q->rear;
}

bool deQueue(SqQueue* q, ElemType* e)
{
	assert(q);
	if (q->front == q->rear)
	{
		return false;
	}
	*e = q->data[q->front];
	q->front++;
	q->front %= (MaxSize + 1);
	return true;
}

void DestroyQueue(SqQueue* q)
{
	assert(q);
	free(q);
}